package com.leo.ibatis.demo.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.leo.ibatis.demo.criteria.BannerdataCriteria;
import com.leo.ibatis.demo.domain.Bannerdata;
import com.leo.ibatis.demo.service.BannerdataService;

public class BannerdataController extends MultiActionController {

	private BannerdataService bannerdataService;

	public void setBannerdataService(BannerdataService bannerdataService) {
		this.bannerdataService = bannerdataService;
	}

	public ModelAndView list(HttpServletRequest request, HttpServletResponse response) throws Exception {
		BannerdataCriteria bannerdataCriteria = new BannerdataCriteria();
		bind(request, bannerdataCriteria);
		
		List<Bannerdata> bannerdataList = bannerdataService.listOnPage(bannerdataCriteria);
		
		ModelAndView mav = new ModelAndView("bannerdata/list");
		mav.addObject("bannerdataList", bannerdataList);
		mav.addObject("bannerdataCriteria", bannerdataCriteria);
		
		return mav;
	}

	public ModelAndView detail(HttpServletRequest request, HttpServletResponse response) throws Exception {
		BannerdataCriteria bannerdataCriteria = new BannerdataCriteria();
		bind(request, bannerdataCriteria);
			
		String favcategory = ServletRequestUtils.getRequiredStringParameter(request, "favcategory");

		Bannerdata bannerdata = bannerdataService.select(favcategory);
		
		ModelAndView mav = new ModelAndView("bannerdata/detail");
		mav.addObject("bannerdata", bannerdata);
		mav.addObject("bannerdataCriteria", bannerdataCriteria);
		
		return mav;
	}

	public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String favcategory = ServletRequestUtils.getRequiredStringParameter(request, "favcategory");

		bannerdataService.delete(favcategory);
		
		return new ModelAndView("redirect:bannerdata.do");
	}

}
